<template>
    <div>
        <el-table :data="store.getters['seck/getSeckList']" border style="width: 100%">
            <el-table-column prop="title" label="活动名称" width="180">
            </el-table-column>
            <el-table-column label="状态" width="180">
                <template v-slot="item">
                    <div>
                        <el-tag v-if="item.row.status == 1" type="success">启用</el-tag>
                        <el-tag v-else type="danger">禁用</el-tag>
                    </div>
                </template>
            </el-table-column>
            <el-table-column label="操作">
                <template v-slot="item">
                    <el-button type="primary" size="small" @click="edit(item.row.id)">编辑</el-button>
                    <el-button type="danger" size="small" @click="del(item.row.id)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>
<script lang='ts' setup>
import { defineEmits } from 'vue'
import { useStore } from 'vuex'
import { seckDelete } from '../../request/api'
import { ElMessage, ElMessageBox } from 'element-plus'
let store = useStore()

const emit = defineEmits(['edit'])
//封装一个编辑菜单事件
const edit = (id: number) => {
    emit('edit', id)
}

//封装一个删除事件
const del = (id: number) => {
    seckDelete({ id }).then(res => {
        if (res.code == 200) {
            ElMessageBox.confirm(
                '你确定要删除这条数据吗?',
                '警告',
                {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                }
            )
                .then(() => {
                    ElMessage({
                        type: 'success',
                        message: '删除',
                    })
                    store.dispatch('seck/getSeckListAction')
                })
                .catch(() => {
                    ElMessage({
                        type: 'info',
                        message: '取消删除',
                    })
                })
        }
    })
}
const getSeck = () => {
    store.dispatch('seck/getSeckListAction')
}
getSeck()

</script>
<style lang='less' scoped></style>